# -*- coding:utf-8 -*-
# 2022/1/28 15:59
# author:xwl
import traceback

from sqlalchemy.dialects.mysql import insert

from backend.app.app.db.session_public import session_pub
import backend.app.app.models.db_owi_public_models as  md_pub

# 方案措施基本信息-读库
def read_tb_year_dvpunit_oilstim_planproj_basic():
    try:
        db_datas=session_pub.query(
            md_pub.TbYearDvpunitOilstimPlanprojMessage.DvpUnit_OilStim_PlanProj_ID,
            md_pub.TbYearDvpunitOilstimPlanprojMessage.DvpUnit_OilStim_PlanProj_Name,
            md_pub.TbYearDvpunitOilstimPlanprojMessage.DvpUnit_Name,
            md_pub.TbYearDvpunitOilstimPlanprojMessage.StimPlanProj_StartYear,
            md_pub.TbYearDvpunitOilstimPlanprojMessage.StimPlanProj_EndYear,
            md_pub.TbYearDvpunitOilstimPlanprojMessage.StimPlanProj_Outline,
            md_pub.TbYearDvpunitOilstimPlanprojMessage.Create_User_Name,
            md_pub.TbYearDvpunitOilstimPlanprojMessage.Create_Date,
            md_pub.TbYearDvpunitOilstimPlanprojMessage.Update_Date,
            md_pub.TbYearDvpunitOilstimPlanprojMessage.Remark
        ).all()
        db_datas = [dict(zip(data.keys(), data)) for data in db_datas]
        return db_datas
    except:
        print(traceback.print_exc())
        return False

# 方案措施基本信息-存库
def save_tb_year_dvpunit_oilstim_planproj_basic(save,modify,delete):
    try:
        result=list()
        for data in save:
            session_pub.add(md_pub.TbYearDvpunitOilstimPlanprojMessage(
                DvpUnit_OilStim_PlanProj_ID=data.DvpUnit_OilStim_PlanProj_ID,
                DvpUnit_OilStim_PlanProj_Name=data.DvpUnit_OilStim_PlanProj_Name,
                DvpUnit_Name=data.DvpUnit_Name,
                StimPlanProj_StartYear=data.StimPlanProj_StartYear,
                StimPlanProj_EndYear=data.StimPlanProj_EndYear,
                StimPlanProj_Outline=data.StimPlanProj_Outline
            ))
            session_pub.commit()
            result.append({
                'DvpUnit_OilStim_PlanProj_ID': data.DvpUnit_OilStim_PlanProj_ID,
                'DvpUnit_OilStim_PlanProj_Name': data.DvpUnit_OilStim_PlanProj_Name,
                'DvpUnit_Name': data.DvpUnit_Name,
                'way':'save',
                'result': True
            })
        for data in modify:
            session_pub.query(md_pub.TbYearDvpunitOilstimPlanprojMessage).filter(
                md_pub.TbYearDvpunitOilstimPlanprojMessage.DvpUnit_OilStim_PlanProj_ID == data.DvpUnit_OilStim_PlanProj_ID,
                md_pub.TbYearDvpunitOilstimPlanprojMessage.DvpUnit_OilStim_PlanProj_Name == data.DvpUnit_OilStim_PlanProj_Name,
                md_pub.TbYearDvpunitOilstimPlanprojMessage.DvpUnit_Name == data.DvpUnit_Name
            ).update({
                    'StimPlanProj_StartYear':data.StimPlanProj_StartYear,
                    'StimPlanProj_EndYear':data.StimPlanProj_EndYear,
                    'StimPlanProj_Outline':data.StimPlanProj_Outline
                })
            session_pub.commit()
            result.append({
                'DvpUnit_OilStim_PlanProj_ID': data.DvpUnit_OilStim_PlanProj_ID,
                'DvpUnit_OilStim_PlanProj_Name': data.DvpUnit_OilStim_PlanProj_Name,
                'DvpUnit_Name': data.DvpUnit_Name,
                'way': 'modify',
                'result': True
            })

        for data in delete:
            session_pub.query(md_pub.TbYearDvpunitOilstimPlanprojMessage).filter(
                md_pub.TbYearDvpunitOilstimPlanprojMessage.DvpUnit_OilStim_PlanProj_ID == data.DvpUnit_OilStim_PlanProj_ID,
                md_pub.TbYearDvpunitOilstimPlanprojMessage.DvpUnit_OilStim_PlanProj_Name == data.DvpUnit_OilStim_PlanProj_Name,
                md_pub.TbYearDvpunitOilstimPlanprojMessage.DvpUnit_Name == data.DvpUnit_Name
            ).delete()
            session_pub.commit()
            result.append({
                'DvpUnit_OilStim_PlanProj_ID': data.DvpUnit_OilStim_PlanProj_ID,
                'DvpUnit_OilStim_PlanProj_Name': data.DvpUnit_OilStim_PlanProj_Name,
                'DvpUnit_Name': data.DvpUnit_Name,
                'way': 'delete',
                'result': True
            })
        return result
    except:
        print(traceback.print_exc())
        session_pub.rollback()
        return False

# 单元方案预测效果-读库
def read_tb_year_dvpunit_oilstim_planproj_forecast():
    try:
        db_datas=session_pub.query(
            md_pub.TbYearDvpunitOilstimPlanprojForecast.DvpUnit_OilStim_PlanProj_Name,
            md_pub.TbYearDvpunitOilstimPlanprojForecast.DvpUnit_Name,
            md_pub.TbYearDvpunitOilstimPlanprojForecast.Year,
            md_pub.TbYearDvpunitOilstimPlanprojForecast.StimType_Name,
            md_pub.TbYearDvpunitOilstimPlanprojForecast.Forecast_Method,
            md_pub.TbYearDvpunitOilstimPlanprojForecast.Stim_WellValidRatio,
            md_pub.TbYearDvpunitOilstimPlanprojForecast.Stim_WellNumber_Valid,
            md_pub.TbYearDvpunitOilstimPlanprojForecast.Stim_ValidPeriod_Average,
            md_pub.TbYearDvpunitOilstimPlanprojForecast.Stim_IncreOil_Average,
            md_pub.TbYearDvpunitOilstimPlanprojForecast.Update_Date,
            md_pub.TbYearDvpunitOilstimPlanprojForecast.Remark
        ).all()
        db_datas = [dict(zip(data.keys(), data)) for data in db_datas]
        return db_datas
    except:
        print(traceback.print_exc())
        return False

# 单元方案预测效果-存库
def save_tb_year_dvpunit_oilstim_planproj_forecast(save,modify,delete):
    result=list()
    for data in save:
        try:
            session_pub.add(md_pub.TbYearDvpunitOilstimPlanprojForecast(
                DvpUnit_OilStim_PlanProj_Name=data.DvpUnit_OilStim_PlanProj_Name,
                DvpUnit_Name=data.DvpUnit_Name,
                Year=data.Year,
                StimType_Name=data.StimType_Name,
                Forecast_Method=data.Forecast_Method,
                Stim_WellValidRatio=data.Stim_WellValidRatio,
                Stim_WellNumber_Valid=data.Stim_WellNumber_Valid,
                Stim_ValidPeriod_Average=data.Stim_ValidPeriod_Average,
                Stim_IncreOil_Average=data.Stim_IncreOil_Average,
                Update_Date=data.Update_Date,
                Remark=data.Remark
            ))
            result.append({
                'DvpUnit_OilStim_PlanProj_Name': data.DvpUnit_OilStim_PlanProj_Name,
                'DvpUnit_Name': data.DvpUnit_Name,
                'Year': data.Year,
                'StimType_Name': data.StimType_Name,
                'way': 'save',
            })
            session_pub.commit()
            result[-1].update({'result':True})
        except:
            print(traceback.print_exc())
            session_pub.rollback()
            result[-1].update({'result': False})

    for data in modify:
        try:
            session_pub.query(md_pub.TbYearDvpunitOilstimPlanprojForecast).filter(
                md_pub.TbYearDvpunitOilstimPlanprojForecast.DvpUnit_OilStim_PlanProj_Name==data.DvpUnit_OilStim_PlanProj_Name,
                md_pub.TbYearDvpunitOilstimPlanprojForecast.DvpUnit_Name==data.DvpUnit_Name,
                md_pub.TbYearDvpunitOilstimPlanprojForecast.Year==data.Year,
                md_pub.TbYearDvpunitOilstimPlanprojForecast.StimType_Name==data.StimType_Name
            ).update({
                    'Forecast_Method' : data.Forecast_Method,
                    'Stim_WellValidRatio' : data.Stim_WellValidRatio,
                    'Stim_WellNumber_Valid' : data.Stim_WellNumber_Valid,
                    'Stim_ValidPeriod_Average' : data.Stim_ValidPeriod_Average,
                    'Stim_IncreOil_Average' :data.Stim_IncreOil_Average,
                    'Update_Date' : data.Update_Date,
                    'Remark' : data.Remark
                })
            result.append({
                'DvpUnit_OilStim_PlanProj_Name': data.DvpUnit_OilStim_PlanProj_Name,
                'DvpUnit_Name': data.DvpUnit_Name,
                'Year': data.Year,
                'StimType_Name': data.StimType_Name,
                'way': 'modify',
            })
            session_pub.commit()
            result[-1].update({'result': True})
        except:
            print(traceback.print_exc())
            session_pub.rollback()
            result[-1].update({'result': False})

        for data in delete:
            try:
                session_pub.query(md_pub.TbYearDvpunitOilstimPlanprojForecast).filter(
                    md_pub.TbYearDvpunitOilstimPlanprojForecast.DvpUnit_OilStim_PlanProj_Name == data.DvpUnit_OilStim_PlanProj_Name,
                    md_pub.TbYearDvpunitOilstimPlanprojForecast.DvpUnit_Name == data.DvpUnit_Name,
                    md_pub.TbYearDvpunitOilstimPlanprojForecast.Year == data.Year,
                    md_pub.TbYearDvpunitOilstimPlanprojForecast.StimType_Name == data.StimType_Name
                ).delete()
                result.append({
                    'DvpUnit_OilStim_PlanProj_Name': data.DvpUnit_OilStim_PlanProj_Name,
                    'DvpUnit_Name': data.DvpUnit_Name,
                    'Year': data.Year,
                    'StimType_Name': data.StimType_Name,
                    'way': 'delete',
                })
                session_pub.commit()
                result[-1].update({'result': True})
            except:
                print(traceback.print_exc())
                session_pub.rollback()
                result[-1].update({'result': False})

    return result


# 单井方案预测效果-读库
def read_tb_oilwellstim_planproj_forecast():
    try:
        db_datas=session_pub.query(
            md_pub.TbOilwellstimPlanprojForecast.DvpUnit_OilStim_PlanProj_Name,
            md_pub.TbOilwellstimPlanprojForecast.Well_Name,
            md_pub.TbOilwellstimPlanprojForecast.Year,
            md_pub.TbOilwellstimPlanprojForecast.StimType_Name,
            md_pub.TbOilwellstimPlanprojForecast.Forecast_Method,
            md_pub.TbOilwellstimPlanprojForecast.Stim_ValidPeriod,
            md_pub.TbOilwellstimPlanprojForecast.Stim_IncreOil,
            md_pub.TbOilwellstimPlanprojForecast.Update_Date,
            md_pub.TbOilwellstimPlanprojForecast.Remark
        ).all()
        db_datas = [dict(zip(data.keys(), data)) for data in db_datas]
        return db_datas
    except:
        print(traceback.print_exc())
        return False

# 单井方案预测效果-存库
def save_tb_oilwellstim_planproj_forecast(save,modify,delete):
    result = list()
    for data in save:
        try:
            session_pub.add(md_pub.TbOilwellstimPlanprojForecast(
                DvpUnit_OilStim_PlanProj_Name=data.DvpUnit_OilStim_PlanProj_Name,
                Well_Name=data.Well_Name,
                Year=data.Year,
                StimType_Name=data.StimType_Name,
                Forecast_Method=data.Forecast_Method,
                Stim_ValidPeriod=data.Stim_ValidPeriod,
                Stim_IncreOil=data.Stim_IncreOil,
                Update_Date=data.Update_Date,
                Remark=data.Remark
            ))
            result.append({
                'DvpUnit_OilStim_PlanProj_Name': data.DvpUnit_OilStim_PlanProj_Name,
                'Well_Name': data.Well_Name,
                'Year': data.Year,
                'StimType_Name': data.StimType_Name,
                'way':'save',
                'result': True
            })
            session_pub.commit()
            result[-1].update({
                'result':True
            })
        except:
            print(traceback.print_exc())
            session_pub.rollback()
            result[-1].update({
                'result': False
            })

    for data in modify:
        try:
            session_pub.query(md_pub.TbOilwellstimPlanprojForecast).filter(
                md_pub.TbOilwellstimPlanprojForecast.DvpUnit_OilStim_PlanProj_Name==data.DvpUnit_OilStim_PlanProj_Name,
                md_pub.TbOilwellstimPlanprojForecast.Well_Name==data.Well_Name,
                md_pub.TbOilwellstimPlanprojForecast.Year==data.Year,
                md_pub.TbOilwellstimPlanprojForecast.StimType_Name==data.StimType_Name
            ).update({
                    'Forecast_Method' : data.Forecast_Method,
                    'Stim_ValidPeriod' : data.Stim_ValidPeriod,
                    'Stim_IncreOil' : data.Stim_IncreOil,
                    'Update_Date' : data.Update_Date,
                    'Remark' : data.Remark
                })
            result.append({
                'DvpUnit_OilStim_PlanProj_Name': data.DvpUnit_OilStim_PlanProj_Name,
                'Well_Name': data.Well_Name,
                'Year': data.Year,
                'StimType_Name': data.StimType_Name,
                'way': 'modify',
                'result': True
            })
            session_pub.commit()
            result[-1].update({
                'result': True
            })
        except:
            print(traceback.print_exc())
            session_pub.rollback()
            result[-1].update({
                'result': False
            })
    for data in delete:
        try:
            session_pub.query(md_pub.TbOilwellstimPlanprojForecast).filter(
                md_pub.TbOilwellstimPlanprojForecast.DvpUnit_OilStim_PlanProj_Name == data.DvpUnit_OilStim_PlanProj_Name,
                md_pub.TbOilwellstimPlanprojForecast.Well_Name == data.Well_Name,
                md_pub.TbOilwellstimPlanprojForecast.Year == data.Year,
                md_pub.TbOilwellstimPlanprojForecast.StimType_Name == data.StimType_Name
            ).delete()
            result.append({
                'DvpUnit_OilStim_PlanProj_Name': data.DvpUnit_OilStim_PlanProj_Name,
                'Well_Name': data.Well_Name,
                'Year': data.Year,
                'StimType_Name': data.StimType_Name,
                'way': 'delete',
                'result': True
            })
            session_pub.commit()
            result[-1].update({
                'result': True
            })
        except:
            print(traceback.print_exc())
            session_pub.rollback()
            result[-1].update({
                'result': False
            })
    return result

# 方案措施作业费用-读库
def read_tb_year_dvpunit_planproj_oilstim_cost():
    try:
        db_datas=session_pub.query(
            md_pub.TbYearDvpunitPlanprojOilstimCost.DvpUnit_OilStim_PlanProj_Name,
            md_pub.TbYearDvpunitPlanprojOilstimCost.DvpUnit_Name,
            md_pub.TbYearDvpunitPlanprojOilstimCost.Year,
            md_pub.TbYearDvpunitPlanprojOilstimCost.StimType_Name,
            md_pub.TbYearDvpunitPlanprojOilstimCost.Stim_Cost,
            md_pub.TbYearDvpunitPlanprojOilstimCost.Remark
        ).all()
        db_datas = [dict(zip(data.keys(), data)) for data in db_datas]
        return db_datas
    except:
        print(traceback.print_exc())
        return False

# 方案措施作业费用-存库
def save_tb_year_dvpunit_planproj_oilstim_cost(save, modify, delete):
    result = list()
    for data in save:
        try:
            session_pub.add(md_pub.TbYearDvpunitPlanprojOilstimCost(
                DvpUnit_OilStim_PlanProj_Name=data.DvpUnit_OilStim_PlanProj_Name,
                DvpUnit_Name=data.DvpUnit_Name,
                Year=data.Year,
                StimType_Name=data.StimType_Name,
                Stim_Cost=data.Stim_Cost,
                Remark=data.Remark
            ))
            session_pub.commit()
            result.append({
                'DvpUnit_OilStim_PlanProj_Name': data.DvpUnit_OilStim_PlanProj_Name,
                'DvpUnit_Name': data.DvpUnit_Name,
                'Year': data.Year,
                'StimType_Name': data.StimType_Name,
                'way': 'save',
                'result': True
            })
            session_pub.commit()
            result[-1].update({
                'result': True
            })
        except:
            print(traceback.print_exc())
            session_pub.rollback()
            result[-1].update({
                'result': False
            })

        for data in modify:
            try:
                session_pub.query(md_pub.TbYearDvpunitPlanprojOilstimCost).filter(
                    md_pub.TbYearDvpunitPlanprojOilstimCost.DvpUnit_OilStim_PlanProj_Name==data.DvpUnit_OilStim_PlanProj_Name,
                    md_pub.TbYearDvpunitPlanprojOilstimCost.DvpUnit_Name==data.DvpUnit_Name,
                    md_pub.TbYearDvpunitPlanprojOilstimCost.Year==data.Year,
                    md_pub.TbYearDvpunitPlanprojOilstimCost.StimType_Name==data.StimType_Name
                ).update({
                        'Stim_Cost' : data.Stim_Cost,
                        'Remark' : data.Remark
                    })
                result.append({
                    'DvpUnit_OilStim_PlanProj_Name': data.DvpUnit_OilStim_PlanProj_Name,
                    'DvpUnit_Name': data.DvpUnit_Name,
                    'Year': data.Year,
                    'StimType_Name': data.StimType_Name,
                    'way': 'modify',
                    'result': True
                })
                session_pub.commit()
                result[-1].update({
                    'result': True
                })
            except:
                print(traceback.print_exc())
                session_pub.rollback()
                result[-1].update({
                    'result': False
                })
    for data in delete:
        try:
            session_pub.query(md_pub.TbYearDvpunitPlanprojOilstimCost).filter(
                md_pub.TbYearDvpunitPlanprojOilstimCost.DvpUnit_OilStim_PlanProj_Name == data.DvpUnit_OilStim_PlanProj_Name,
                md_pub.TbYearDvpunitPlanprojOilstimCost.DvpUnit_Name == data.DvpUnit_Name,
                md_pub.TbYearDvpunitPlanprojOilstimCost.Year == data.Year,
                md_pub.TbYearDvpunitPlanprojOilstimCost.StimType_Name == data.StimType_Name
            ).delete()
            result.append({
                'DvpUnit_OilStim_PlanProj_Name': data.DvpUnit_OilStim_PlanProj_Name,
                'DvpUnit_Name': data.DvpUnit_Name,
                'Year': data.Year,
                'StimType_Name': data.StimType_Name,
                'way': 'delete',
                'result': True
            })
            session_pub.commit()
            result[-1].update({
                'result': True
            })
        except:
            print(traceback.print_exc())
            session_pub.rollback()
            result[-1].update({
                'result': False
            })
    return result

# 方案措施原油价格-读库
def read_tb_year_dvpunit_planproj_oilprice():
    try:
        db_datas=session_pub.query(
            md_pub.TbYearDvpunitPlanprojOilprice.DvpUnit_OilStimulate_PlanProj_Name,
            md_pub.TbYearDvpunitPlanprojOilprice.DvpUnit_Name,
            md_pub.TbYearDvpunitPlanprojOilprice.Year,
            md_pub.TbYearDvpunitPlanprojOilprice.Oil_CommodityRatio,
            md_pub.TbYearDvpunitPlanprojOilprice.Oil_Price,
            md_pub.TbYearDvpunitPlanprojOilprice.Remark
        ).all()
        db_datas = [dict(zip(data.keys(), data)) for data in db_datas]
        return db_datas
    except:
        print(traceback.print_exc())
        return False

# 方案措施原油价格-存库
def save_tb_year_dvpunit_planproj_oilprice(save, modify, delete):
    result = list()
    for data in save:
        try:
            session_pub.add(md_pub.TbYearDvpunitPlanprojOilprice(
                DvpUnit_OilStimulate_PlanProj_Name=data.DvpUnit_OilStimulate_PlanProj_Name,
                DvpUnit_Name=data.DvpUnit_Name,
                Year=data.Year,
                Oil_CommodityRatio=data.Oil_CommodityRatio,
                Oil_Price=data.Oil_Price,
                Remark=data.Remark
            ))
            result.append({
                'DvpUnit_OilStimulate_PlanProj_Name': data.DvpUnit_OilStimulate_PlanProj_Name,
                'DvpUnit_Name': data.DvpUnit_Name,
                'Year': data.Year,
                'way': 'save',
                'result': True
            })
            session_pub.commit()
            result[-1].update({
                'result': True
            })
        except:
            print(traceback.print_exc())
            session_pub.rollback()
            result[-1].update({
                'result': False
            })

    for data in modify:
        try:
            session_pub.query(md_pub.TbYearDvpunitPlanprojOilprice).filter(
                md_pub.TbYearDvpunitPlanprojOilprice.DvpUnit_OilStimulate_PlanProj_Name==data.DvpUnit_OilStimulate_PlanProj_Name,
                md_pub.TbYearDvpunitPlanprojOilprice.DvpUnit_Name==data.DvpUnit_Name,
                md_pub.TbYearDvpunitPlanprojOilprice.Year==data.Year
            ).update({
                    'Oil_CommodityRatio' : data.Oil_CommodityRatio,
                    'Oil_Price' : data.Oil_Price,
                    'Remark' : data.Remark
                })
            result.append({
                'DvpUnit_OilStimulate_PlanProj_Name': data.DvpUnit_OilStimulate_PlanProj_Name,
                'DvpUnit_Name': data.DvpUnit_Name,
                'Year': data.Year,
                'way': 'modify',
                'result': True
            })
            session_pub.commit()
            result[-1].update({
                'result': True
            })
        except:
            print(traceback.print_exc())
            session_pub.rollback()
            result[-1].update({
                'result': False
            })
    for data in delete:
        try:
            session_pub.query(md_pub.TbYearDvpunitPlanprojOilprice).filter(
                md_pub.TbYearDvpunitPlanprojOilprice.DvpUnit_OilStimulate_PlanProj_Name==data.DvpUnit_OilStimulate_PlanProj_Name,
                md_pub.TbYearDvpunitPlanprojOilprice.DvpUnit_Name==data.DvpUnit_Name,
                md_pub.TbYearDvpunitPlanprojOilprice.Year==data.Year
            ).delete()
            result.append({
                'DvpUnit_OilStimulate_PlanProj_Name': data.DvpUnit_OilStimulate_PlanProj_Name,
                'DvpUnit_Name': data.DvpUnit_Name,
                'Year': data.Year,
                'way': 'delete',
                'result': True
            })
            session_pub.commit()
            result[-1].update({
                'result': True
            })
        except:
            print(traceback.print_exc())
            session_pub.rollback()
            result[-1].update({
                'result': False
            })
    return result

# 方案增油操作成本-读库
def read_tb_year_dvpunit_planproj_oilprodcost():
    try:
        db_datas=session_pub.query(
            md_pub.TbYearDvpunitPlanprojOilprodcost.DvpUnit_OilStim_PlanProj_Name,
            md_pub.TbYearDvpunitPlanprojOilprodcost.DvpUnit_Name,
            md_pub.TbYearDvpunitPlanprojOilprodcost.Year,
            md_pub.TbYearDvpunitPlanprojOilprodcost.Oil_OprCost,
            md_pub.TbYearDvpunitPlanprojOilprodcost.FuelCost,
            md_pub.TbYearDvpunitPlanprojOilprodcost.Power_Cost,
            md_pub.TbYearDvpunitPlanprojOilprodcost.FluidDispose_Cost,
            md_pub.TbYearDvpunitPlanprojOilprodcost.OilDisplaceAgent_Cost,
            md_pub.TbYearDvpunitPlanprojOilprodcost.NGLRecovery_Cost,
            md_pub.TbYearDvpunitPlanprojOilprodcost.Transp_Cost,
            md_pub.TbYearDvpunitPlanprojOilprodcost.WellTest_Cost,
            md_pub.TbYearDvpunitPlanprojOilprodcost.Other_Cost,
            md_pub.TbYearDvpunitPlanprojOilprodcost.Depreciation_Cost,
            md_pub.TbYearDvpunitPlanprojOilprodcost.Remark
        ).all()
        db_datas = [dict(zip(data.keys(), data)) for data in db_datas]
        return db_datas
    except:
        print(traceback.print_exc())
        return False

# 方案增油操作成本-存库
def save_tb_year_dvpunit_planproj_oilprodcost(save, modify, delete):
    result = list()
    for data in save:
        try:
            session_pub.add(md_pub.TbYearDvpunitPlanprojOilprodcost(
                DvpUnit_OilStim_PlanProj_Name=data.DvpUnit_OilStim_PlanProj_Name,
                DvpUnit_Name=data.DvpUnit_Name,
                Year=data.Year,
                Oil_OprCost=data.Oil_OprCost,
                FuelCost=data.FuelCost,
                Power_Cost=data.Power_Cost,
                FluidDispose_Cost=data.FluidDispose_Cost,
                OilDisplaceAgent_Cost=data.OilDisplaceAgent_Cost,
                NGLRecovery_Cost=data.NGLRecovery_Cost,
                Transp_Cost=data.Transp_Cost,
                WellTest_Cost=data.WellTest_Cost,
                Other_Cost=data.Other_Cost,
                Depreciation_Cost=data.Depreciation_Cost,
                Remark=data.Remark
            ))
            result.append({
                'DvpUnit_OilStim_PlanProj_Name': data.DvpUnit_OilStim_PlanProj_Name,
                'DvpUnit_Name': data.DvpUnit_Name,
                'Year': data.Year,
                'way': 'save',
                'result': True
            })
            session_pub.commit()
            result[-1].update({
                'result': True
            })
        except:
            print(traceback.print_exc())
            session_pub.rollback()
            result[-1].update({
                'result': False
            })

    for data in modify:
        print('data:',data)
        try:
            session_pub.query(md_pub.TbYearDvpunitPlanprojOilprodcost).filter(
                md_pub.TbYearDvpunitPlanprojOilprodcost.DvpUnit_OilStim_PlanProj_Name==data.DvpUnit_OilStim_PlanProj_Name,
                md_pub.TbYearDvpunitPlanprojOilprodcost.DvpUnit_Name==data.DvpUnit_Name,
                md_pub.TbYearDvpunitPlanprojOilprodcost.Year==data.Year
            ).update({
                    'Oil_OprCost':data.Oil_OprCost,
                    'FuelCost':data.FuelCost,
                    'Power_Cost':data.Power_Cost,
                    'FluidDispose_Cost':data.FluidDispose_Cost,
                    'OilDisplaceAgent_Cost':data.OilDisplaceAgent_Cost,
                    'NGLRecovery_Cost':data.NGLRecovery_Cost,
                    'Transp_Cost':data.Transp_Cost,
                    'WellTest_Cost':data.WellTest_Cost,
                    'Other_Cost':data.Other_Cost,
                    'Depreciation_Cost':data.Depreciation_Cost,
                    'Remark':data.Remark
                })
            result.append({
                'DvpUnit_OilStim_PlanProj_Name': data.DvpUnit_OilStim_PlanProj_Name,
                'DvpUnit_Name': data.DvpUnit_Name,
                'Year': data.Year,
                'way': 'modify',
                'result': True
            })
            session_pub.commit()
            result[-1].update({
                'result': True
            })
        except:
            print(traceback.print_exc())
            session_pub.rollback()
            result[-1].update({
                'result': False
            })

    for data in delete:
        try:
            session_pub.query(md_pub.TbYearDvpunitPlanprojOilprodcost).filter(
                md_pub.TbYearDvpunitPlanprojOilprodcost.DvpUnit_OilStim_PlanProj_Name==data.DvpUnit_OilStim_PlanProj_Name,
                md_pub.TbYearDvpunitPlanprojOilprodcost.DvpUnit_Name==data.DvpUnit_Name,
                md_pub.TbYearDvpunitPlanprojOilprodcost.Year==data.Year
            ).delete()
            result.append({
                'DvpUnit_OilStim_PlanProj_Name': data.DvpUnit_OilStim_PlanProj_Name,
                'DvpUnit_Name': data.DvpUnit_Name,
                'Year': data.Year,
                'way': 'delete',
                'result': True
            })
            session_pub.commit()
            result[-1].update({
                'result': True
            })
        except:
            print(traceback.print_exc())
            session_pub.rollback()
            result[-1].update({
                'result': False
            })
    return result

# 方案增油销售成本-读库
def read_tb_year_dvpunit_oilsalecost_ratio():
    try:
        db_datas=session_pub.query(
            md_pub.TbYearDvpunitPlanprojOilsalecostRatio.DvpUnit_OilStim_PlanProj_Name,
            md_pub.TbYearDvpunitPlanprojOilsalecostRatio.DvpUnit_Name,
            md_pub.TbYearDvpunitPlanprojOilsalecostRatio.Year,
            md_pub.TbYearDvpunitPlanprojOilsalecostRatio.OilSale_TotalTaxRatio,
            md_pub.TbYearDvpunitPlanprojOilsalecostRatio.AddedValue_TaxRatio,
            md_pub.TbYearDvpunitPlanprojOilsalecostRatio.Resource_TaxRatio,
            md_pub.TbYearDvpunitPlanprojOilsalecostRatio.EduAdd_TaxRatio,
            md_pub.TbYearDvpunitPlanprojOilsalecostRatio.CityDvpAdd_TaxRate,
            md_pub.TbYearDvpunitPlanprojOilsalecostRatio.Income_TaxRate,
            md_pub.TbYearDvpunitPlanprojOilsalecostRatio.ManageCost_Ratio,
            md_pub.TbYearDvpunitPlanprojOilsalecostRatio.Remark
        ).all()
        db_datas = [dict(zip(data.keys(), data)) for data in db_datas]
        return db_datas
    except:
        print(traceback.print_exc())
        return False

# 方案增油销售成本-存库
def save_tb_year_dvpunit_oilsalecost_ratio(save, modify, delete):
    result = list()
    for data in save:
        try:
            session_pub.add(md_pub.TbYearDvpunitPlanprojOilsalecostRatio(
                DvpUnit_OilStim_PlanProj_Name=data.DvpUnit_OilStim_PlanProj_Name,
                DvpUnit_Name=data.DvpUnit_Name,
                Year=data.Year,
                OilSale_TotalTaxRatio=data.OilSale_TotalTaxRatio,
                AddedValue_TaxRatio=data.AddedValue_TaxRatio,
                Resource_TaxRatio=data.Resource_TaxRatio,
                EduAdd_TaxRatio=data.EduAdd_TaxRatio,
                CityDvpAdd_TaxRate=data.CityDvpAdd_TaxRate,
                Income_TaxRate=data.Income_TaxRate,
                ManageCost_Ratio=data.ManageCost_Ratio,
                Remark=data.Remark
            ))
            result.append({
                'DvpUnit_OilStim_PlanProj_Name': data.DvpUnit_OilStim_PlanProj_Name,
                'DvpUnit_Name': data.DvpUnit_Name,
                'Year': data.Year,
                'way': 'save',
                'result': True
            })
            session_pub.commit()
            result[-1].update({
                'result': True
            })
        except:
            print(traceback.print_exc())
            session_pub.rollback()
            result[-1].update({
                'result': False
            })

    for data in modify:
        print('data:',data)
        try:
            session_pub.query(md_pub.TbYearDvpunitPlanprojOilsalecostRatio).filter(
                md_pub.TbYearDvpunitPlanprojOilsalecostRatio.DvpUnit_OilStim_PlanProj_Name==data.DvpUnit_OilStim_PlanProj_Name,
                md_pub.TbYearDvpunitPlanprojOilsalecostRatio.DvpUnit_Name==data.DvpUnit_Name,
                md_pub.TbYearDvpunitPlanprojOilsalecostRatio.Year==data.Year
            ).update({
                    'OilSale_TotalTaxRatio':data.OilSale_TotalTaxRatio,
                    'AddedValue_TaxRatio':data.AddedValue_TaxRatio,
                    'Resource_TaxRatio':data.Resource_TaxRatio,
                    'EduAdd_TaxRatio':data.EduAdd_TaxRatio,
                    'CityDvpAdd_TaxRate':data.CityDvpAdd_TaxRate,
                    'Income_TaxRate':data.Income_TaxRate,
                    'ManageCost_Ratio':data.ManageCost_Ratio,
                    'Remark':data.Remark
                })
            result.append({
                'DvpUnit_OilStim_PlanProj_Name': data.DvpUnit_OilStim_PlanProj_Name,
                'DvpUnit_Name': data.DvpUnit_Name,
                'Year': data.Year,
                'way': 'modify',
                'result': True
            })
            session_pub.commit()
            result[-1].update({
                'result': True
            })
        except:
            print(traceback.print_exc())
            session_pub.rollback()
            result[-1].update({
                'result': False
            })

    for data in delete:
        try:
            session_pub.query(md_pub.TbYearDvpunitPlanprojOilsalecostRatio).filter(
                md_pub.TbYearDvpunitPlanprojOilsalecostRatio.DvpUnit_OilStim_PlanProj_Name==data.DvpUnit_OilStim_PlanProj_Name,
                md_pub.TbYearDvpunitPlanprojOilsalecostRatio.DvpUnit_Name==data.DvpUnit_Name,
                md_pub.TbYearDvpunitPlanprojOilsalecostRatio.Year==data.Year
            ).delete()
            result.append({
                'DvpUnit_OilStim_PlanProj_Name': data.DvpUnit_OilStim_PlanProj_Name,
                'DvpUnit_Name': data.DvpUnit_Name,
                'Year': data.Year,
                'way': 'delete',
                'result': True
            })
            session_pub.commit()
            result[-1].update({
                'result': True
            })
        except:
            print(traceback.print_exc())
            session_pub.rollback()
            result[-1].update({
                'result': False
            })
    return result

# 方案资金成本-读库
def read_tb_year_dvpunit_planproj_discount():
    try:
        db_datas=session_pub.query(
            md_pub.TbYearDvpunitPlanprojDiscount.DvpUnit_OilStimulate_PlanProj_Name,
            md_pub.TbYearDvpunitPlanprojDiscount.DvpUnit_Name,
            md_pub.TbYearDvpunitPlanprojDiscount.Year,
            md_pub.TbYearDvpunitPlanprojDiscount.Money_Discount,
            md_pub.TbYearDvpunitPlanprojDiscount.Remark
        ).all()
        db_datas = [dict(zip(data.keys(), data)) for data in db_datas]
        return db_datas
    except:
        print(traceback.print_exc())
        return False


# 方案资金成本-存库
def save_tb_year_dvpunit_planproj_discount(save, modify, delete):
    result = list()
    for data in save:
        try:
            session_pub.add(md_pub.TbYearDvpunitPlanprojDiscount(
                DvpUnit_OilStimulate_PlanProj_Name=data.DvpUnit_OilStimulate_PlanProj_Name,
                DvpUnit_Name=data.DvpUnit_Name,
                Year=data.Year,
                Money_Discount=data.Money_Discount,
                Remark=data.Remark
            ))
            result.append({
                'DvpUnit_OilStimulate_PlanProj_Name': data.DvpUnit_OilStimulate_PlanProj_Name,
                'DvpUnit_Name': data.DvpUnit_Name,
                'Year': data.Year,
                'way': 'save',
                'result': True
            })
            session_pub.commit()
            result[-1].update({
                'result': True
            })
        except:
            print(traceback.print_exc())
            session_pub.rollback()
            result[-1].update({
                'result': False
            })

    for data in modify:
        try:
            session_pub.query(md_pub.TbYearDvpunitPlanprojDiscount).filter(
                md_pub.TbYearDvpunitPlanprojDiscount.DvpUnit_OilStimulate_PlanProj_Name == data.DvpUnit_OilStimulate_PlanProj_Name,
                md_pub.TbYearDvpunitPlanprojDiscount.DvpUnit_Name == data.DvpUnit_Name,
                md_pub.TbYearDvpunitPlanprojDiscount.Year == data.Year
            ).update({
                'Money_Discount': data.Money_Discount,
                'Remark': data.Remark
            })
            result.append({
                'DvpUnit_OilStimulate_PlanProj_Name': data.DvpUnit_OilStimulate_PlanProj_Name,
                'DvpUnit_Name': data.DvpUnit_Name,
                'Year': data.Year,
                'way': 'modify',
                'result': True
            })
            session_pub.commit()
            result[-1].update({
                'result': True
            })
        except:
            print(traceback.print_exc())
            session_pub.rollback()
            result[-1].update({
                'result': False
            })

    for data in delete:
        try:
            session_pub.query(md_pub.TbYearDvpunitPlanprojDiscount).filter(
                md_pub.TbYearDvpunitPlanprojDiscount.DvpUnit_OilStimulate_PlanProj_Name == data.DvpUnit_OilStimulate_PlanProj_Name,
                md_pub.TbYearDvpunitPlanprojDiscount.DvpUnit_Name == data.DvpUnit_Name,
                md_pub.TbYearDvpunitPlanprojDiscount.Year == data.Year
            ).delete()
            result.append({
                'DvpUnit_OilStimulate_PlanProj_Name': data.DvpUnit_OilStimulate_PlanProj_Name,
                'DvpUnit_Name': data.DvpUnit_Name,
                'Year': data.Year,
                'way': 'delete',
                'result': True
            })
            session_pub.commit()
            result[-1].update({
                'result': True
            })
        except:
            print(traceback.print_exc())
            session_pub.rollback()
            result[-1].update({
                'result': False
            })
    return result

# 单元方案经济评价结果-读库
def read_tb_year_dvpunit_oilstim_planproj_evaluate_result():
    try:
        db_datas=session_pub.query(
            md_pub.TbYearDvpunitOilstimPlanprojEvaluateResult.DvpUnit_OilStim_PlanProj_Name,
            md_pub.TbYearDvpunitOilstimPlanprojEvaluateResult.DvpUnit_Name,
            md_pub.TbYearDvpunitOilstimPlanprojEvaluateResult.Year,
            md_pub.TbYearDvpunitOilstimPlanprojEvaluateResult.StimType_Name,
            md_pub.TbYearDvpunitOilstimPlanprojEvaluateResult.Stim_WellValidRatio,
            md_pub.TbYearDvpunitOilstimPlanprojEvaluateResult.Stim_WellNumber_Valid,
            md_pub.TbYearDvpunitOilstimPlanprojEvaluateResult.Stim_ValidPeriod_Average,
            md_pub.TbYearDvpunitOilstimPlanprojEvaluateResult.Stim_IncreOil_Average,
            md_pub.TbYearDvpunitOilstimPlanprojEvaluateResult.StimOil_CommodityRatio,
            md_pub.TbYearDvpunitOilstimPlanprojEvaluateResult.Oil_Price,
            md_pub.TbYearDvpunitOilstimPlanprojEvaluateResult.OilSale_TotalTaxRatio,
            md_pub.TbYearDvpunitOilstimPlanprojEvaluateResult.Money_Discount,
            md_pub.TbYearDvpunitOilstimPlanprojEvaluateResult.Oil_OprCost,
            md_pub.TbYearDvpunitOilstimPlanprojEvaluateResult.StimCost_Average,
            md_pub.TbYearDvpunitOilstimPlanprojEvaluateResult.StimOil_WellOprCost_Average,
            md_pub.TbYearDvpunitOilstimPlanprojEvaluateResult.StimOil_Total_Tax_Average,
            md_pub.TbYearDvpunitOilstimPlanprojEvaluateResult.StimOil_Gross_SalesIncome_Average,
            md_pub.TbYearDvpunitOilstimPlanprojEvaluateResult.StimOil_Static_Gains_Average,
            md_pub.TbYearDvpunitOilstimPlanprojEvaluateResult.StimOil_NPV_Average,
            md_pub.TbYearDvpunitOilstimPlanprojEvaluateResult.StimOil_ROI,
            md_pub.TbYearDvpunitOilstimPlanprojEvaluateResult.StimOil_NPVR,
            md_pub.TbYearDvpunitOilstimPlanprojEvaluateResult.StimOil_FIRR,
            md_pub.TbYearDvpunitOilstimPlanprojEvaluateResult.Stim_IncreOil_Critical_Average,
            md_pub.TbYearDvpunitOilstimPlanprojEvaluateResult.StimOil_Price_Critical,
            md_pub.TbYearDvpunitOilstimPlanprojEvaluateResult.Remark
        ).all()
        db_datas = [dict(zip(data.keys(), data)) for data in db_datas]
        return db_datas
    except:
        print(traceback.print_exc())
        return False

# 单元方案经济评价结果-存库
def save_tb_year_dvpunit_oilstim_planproj_evaluate_result(save, modify, delete):
    result = list()
    for data in save:
        try:
            session_pub.add(md_pub.TbYearDvpunitOilstimPlanprojEvaluateResult(
                DvpUnit_OilStim_PlanProj_Name= data.DvpUnit_OilStim_PlanProj_Name,
                DvpUnit_Name= data.DvpUnit_Name,
                Year= data.Year,
                StimType_Name= data.StimType_Name,
                Stim_WellValidRatio= data.Stim_WellValidRatio,
                Stim_WellNumber_Valid= data.Stim_WellNumber_Valid,
                Stim_ValidPeriod_Average= data.Stim_ValidPeriod_Average,
                Stim_IncreOil_Average= data.Stim_IncreOil_Average,
                StimOil_CommodityRatio= data.StimOil_CommodityRatio,
                Oil_Price= data.Oil_Price,
                OilSale_TotalTaxRatio= data.OilSale_TotalTaxRatio,
                Money_Discount= data.Money_Discount,
                Oil_OprCost= data.Oil_OprCost,
                StimCost_Average= data.StimCost_Average,
                StimOil_WellOprCost_Average= data.StimOil_WellOprCost_Average,
                StimOil_Total_Tax_Average= data.StimOil_Total_Tax_Average,
                StimOil_Gross_SalesIncome_Average= data.StimOil_Gross_SalesIncome_Average,
                StimOil_Static_Gains_Average= data.StimOil_Static_Gains_Average,
                StimOil_NPV_Average= data.StimOil_NPV_Average,
                StimOil_ROI= data.StimOil_ROI,
                StimOil_NPVR= data.StimOil_NPVR,
                StimOil_FIRR= data.StimOil_FIRR,
                Stim_IncreOil_Critical_Average= data.Stim_IncreOil_Critical_Average,
                StimOil_Price_Critical= data.StimOil_Price_Critical,
                Remark= data.Remark
            ))
            result.append({
                'DvpUnit_OilStim_PlanProj_Name': data.DvpUnit_OilStim_PlanProj_Name,
                'DvpUnit_Name': data.DvpUnit_Name,
                'Year': data.Year,
                'StimType_Name': data.StimType_Name,
                'way': 'save',
                'result': True
            })
            session_pub.commit()
            result[-1].update({
                'result': True
            })
        except:
            print(traceback.print_exc())
            session_pub.rollback()
            result[-1].update({
                'result': False
            })

    for data in modify:
        try:
            session_pub.query(md_pub.TbYearDvpunitOilstimPlanprojEvaluateResult).filter(
                md_pub.TbYearDvpunitOilstimPlanprojEvaluateResult.DvpUnit_OilStim_PlanProj_Name == data.DvpUnit_OilStim_PlanProj_Name,
                md_pub.TbYearDvpunitOilstimPlanprojEvaluateResult.DvpUnit_Name == data.DvpUnit_Name,
                md_pub.TbYearDvpunitOilstimPlanprojEvaluateResult.Year == data.Year,
                md_pub.TbYearDvpunitOilstimPlanprojEvaluateResult.StimType_Name == data.StimType_Name
            ).update({
                'Stim_WellValidRatio': data.Stim_WellValidRatio,
                'Stim_WellNumber_Valid': data.Stim_WellNumber_Valid,
                'Stim_ValidPeriod_Average': data.Stim_ValidPeriod_Average,
                'Stim_IncreOil_Average': data.Stim_IncreOil_Average,
                'StimOil_CommodityRatio': data.StimOil_CommodityRatio,
                'Oil_Price': data.Oil_Price,
                'OilSale_TotalTaxRatio': data.OilSale_TotalTaxRatio,
                'Money_Discount': data.Money_Discount,
                'Oil_OprCost': data.Oil_OprCost,
                'StimCost_Average': data.StimCost_Average,
                'StimOil_WellOprCost_Average': data.StimOil_WellOprCost_Average,
                'StimOil_Total_Tax_Average': data.StimOil_Total_Tax_Average,
                'StimOil_Gross_SalesIncome_Average': data.StimOil_Gross_SalesIncome_Average,
                'StimOil_Static_Gains_Average': data.StimOil_Static_Gains_Average,
                'StimOil_NPV_Average': data.StimOil_NPV_Average,
                'StimOil_ROI': data.StimOil_ROI,
                'StimOil_NPVR': data.StimOil_NPVR,
                'StimOil_FIRR': data.StimOil_FIRR,
                'Stim_IncreOil_Critical_Average': data.Stim_IncreOil_Critical_Average,
                'StimOil_Price_Critical': data.StimOil_Price_Critical,
                'Remark': data.Remark
            })
            result.append({
                'DvpUnit_OilStim_PlanProj_Name': data.DvpUnit_OilStim_PlanProj_Name,
                'DvpUnit_Name': data.DvpUnit_Name,
                'Year': data.Year,
                'StimType_Name': data.StimType_Name,
                'way': 'modify',
                'result': True
            })
            session_pub.commit()
            result[-1].update({
                'result': True
            })
        except:
            print(traceback.print_exc())
            session_pub.rollback()
            result[-1].update({
                'result': False
            })

    for data in delete:
        try:
            session_pub.query(md_pub.TbYearDvpunitOilstimPlanprojEvaluateResult).filter(
                md_pub.TbYearDvpunitOilstimPlanprojEvaluateResult.DvpUnit_OilStim_PlanProj_Name == data.DvpUnit_OilStim_PlanProj_Name,
                md_pub.TbYearDvpunitOilstimPlanprojEvaluateResult.DvpUnit_Name == data.DvpUnit_Name,
                md_pub.TbYearDvpunitOilstimPlanprojEvaluateResult.Year == data.Year,
                md_pub.TbYearDvpunitOilstimPlanprojEvaluateResult.StimType_Name == data.StimType_Name
            ).delete()
            result.append({
                'DvpUnit_OilStim_PlanProj_Name': data.DvpUnit_OilStim_PlanProj_Name,
                'DvpUnit_Name': data.DvpUnit_Name,
                'Year': data.Year,
                'StimType_Name': data.StimType_Name,
                'way': 'delete',
                'result': True
            })
            session_pub.commit()
            result[-1].update({
                'result': True
            })
        except:
            print(traceback.print_exc())
            session_pub.rollback()
            result[-1].update({
                'result': False
            })
    return result

# 单井方案经济评价结果-读库
def read_tb_oilwellstim_planproj_evaluate_result():
    try:
        db_datas=session_pub.query(
            md_pub.TbOilwellstimPlanprojEvaluateResult.DvpUnit_OilStim_PlanProj_Name,
            md_pub.TbOilwellstimPlanprojEvaluateResult.Well_Name,
            md_pub.TbOilwellstimPlanprojEvaluateResult.Year,
            md_pub.TbOilwellstimPlanprojEvaluateResult.StimType_Name,
            md_pub.TbOilwellstimPlanprojEvaluateResult.Stim_ValidPeriod,
            md_pub.TbOilwellstimPlanprojEvaluateResult.Stim_IncreOil,
            md_pub.TbOilwellstimPlanprojEvaluateResult.StimOil_CommodityRatio,
            md_pub.TbOilwellstimPlanprojEvaluateResult.Oil_Price,
            md_pub.TbOilwellstimPlanprojEvaluateResult.OilSale_TotalTaxRatio,
            md_pub.TbOilwellstimPlanprojEvaluateResult.Money_Discount,
            md_pub.TbOilwellstimPlanprojEvaluateResult.Oil_OprCost,
            md_pub.TbOilwellstimPlanprojEvaluateResult.StimCost,
            md_pub.TbOilwellstimPlanprojEvaluateResult.StimOil_WellOprCost,
            md_pub.TbOilwellstimPlanprojEvaluateResult.StimOil_Total_Tax,
            md_pub.TbOilwellstimPlanprojEvaluateResult.StimOil_Gross_SalesIncome,
            md_pub.TbOilwellstimPlanprojEvaluateResult.StimOil_Static_Gains,
            md_pub.TbOilwellstimPlanprojEvaluateResult.StimOil_NPV,
            md_pub.TbOilwellstimPlanprojEvaluateResult.StimOil_ROI,
            md_pub.TbOilwellstimPlanprojEvaluateResult.StimOil_NPVR,
            md_pub.TbOilwellstimPlanprojEvaluateResult.StimOil_FIRR,
            md_pub.TbOilwellstimPlanprojEvaluateResult.Stim_IncreOil_Critical,
            md_pub.TbOilwellstimPlanprojEvaluateResult.StimOil_Price_Critical,
            md_pub.TbOilwellstimPlanprojEvaluateResult.Remark
        ).all()
        db_datas = [dict(zip(data.keys(), data)) for data in db_datas]
        return db_datas
    except:
        print(traceback.print_exc())
        return False

# 单元方案经济评价结果-存库
def save_tb_oilwellstim_planproj_evaluate_result(save, modify, delete):
    result = list()
    for data in save:
        try:
            session_pub.add(md_pub.TbOilwellstimPlanprojEvaluateResult(
                DvpUnit_OilStim_PlanProj_Name=data.DvpUnit_OilStim_PlanProj_Name,
                Well_Name=data.Well_Name,
                Year=data.Year,
                StimType_Name=data.StimType_Name,
                Stim_ValidPeriod=data.Stim_ValidPeriod,
                Stim_IncreOil=data.Stim_IncreOil,
                StimOil_CommodityRatio=data.StimOil_CommodityRatio,
                Oil_Price=data.Oil_Price,
                OilSale_TotalTaxRatio=data.OilSale_TotalTaxRatio,
                Money_Discount=data.Money_Discount,
                Oil_OprCost=data.Oil_OprCost,
                StimCost=data.StimCost,
                StimOil_WellOprCost=data.StimOil_WellOprCost,
                StimOil_Total_Tax=data.StimOil_Total_Tax,
                StimOil_Gross_SalesIncome=data.StimOil_Gross_SalesIncome,
                StimOil_Static_Gains=data.StimOil_Static_Gains,
                StimOil_NPV=data.StimOil_NPV,
                StimOil_ROI=data.StimOil_ROI,
                StimOil_NPVR=data.StimOil_NPVR,
                StimOil_FIRR=data.StimOil_FIRR,
                Stim_IncreOil_Critical=data.Stim_IncreOil_Critical,
                StimOil_Price_Critical=data.StimOil_Price_Critical,
                Remark=data.Remark
            ))
            result.append({
                'DvpUnit_OilStim_PlanProj_Name': data.DvpUnit_OilStim_PlanProj_Name,
                'Well_Name': data.Well_Name,
                'Year': data.Year,
                'StimType_Name': data.StimType_Name,
                'way': 'save',
                'result': True
            })
            session_pub.commit()
            result[-1].update({
                'result': True
            })
        except:
            print(traceback.print_exc())
            session_pub.rollback()
            result[-1].update({
                'result': False
            })

    for data in modify:
        try:
            session_pub.query(md_pub.TbOilwellstimPlanprojEvaluateResult).filter(
                md_pub.TbOilwellstimPlanprojEvaluateResult.DvpUnit_OilStim_PlanProj_Name == data.DvpUnit_OilStim_PlanProj_Name,
                md_pub.TbOilwellstimPlanprojEvaluateResult.Well_Name == data.Well_Name,
                md_pub.TbOilwellstimPlanprojEvaluateResult.Year == data.Year,
                md_pub.TbOilwellstimPlanprojEvaluateResult.StimType_Name == data.StimType_Name
            ).update({
                    'Stim_ValidPeriod':data.Stim_ValidPeriod,
                    'Stim_IncreOil':data.Stim_IncreOil,
                    'StimOil_CommodityRatio':data.StimOil_CommodityRatio,
                    'Oil_Price':data.Oil_Price,
                    'OilSale_TotalTaxRatio':data.OilSale_TotalTaxRatio,
                    'Money_Discount':data.Money_Discount,
                    'Oil_OprCost':data.Oil_OprCost,
                    'StimCost':data.StimCost,
                    'StimOil_WellOprCost':data.StimOil_WellOprCost,
                    'StimOil_Total_Tax':data.StimOil_Total_Tax,
                    'StimOil_Gross_SalesIncome':data.StimOil_Gross_SalesIncome,
                    'StimOil_Static_Gains':data.StimOil_Static_Gains,
                    'StimOil_NPV':data.StimOil_NPV,
                    'StimOil_ROI':data.StimOil_ROI,
                    'StimOil_NPVR':data.StimOil_NPVR,
                    'StimOil_FIRR':data.StimOil_FIRR,
                    'Stim_IncreOil_Critical':data.Stim_IncreOil_Critical,
                    'StimOil_Price_Critical':data.StimOil_Price_Critical,
                    'Remark':data.Remark
            })
            result.append({
                'DvpUnit_OilStim_PlanProj_Name': data.DvpUnit_OilStim_PlanProj_Name,
                'Well_Name': data.Well_Name,
                'Year': data.Year,
                'StimType_Name': data.StimType_Name,
                'way': 'modify',
                'result': True
            })
            session_pub.commit()
            result[-1].update({
                'result': True
            })
        except:
            print(traceback.print_exc())
            session_pub.rollback()
            result[-1].update({
                'result': False
            })

    for data in delete:
        try:
            session_pub.query(md_pub.TbOilwellstimPlanprojEvaluateResult).filter(
                md_pub.TbOilwellstimPlanprojEvaluateResult.DvpUnit_OilStim_PlanProj_Name == data.DvpUnit_OilStim_PlanProj_Name,
                md_pub.TbOilwellstimPlanprojEvaluateResult.Well_Name == data.Well_Name,
                md_pub.TbOilwellstimPlanprojEvaluateResult.Year == data.Year,
                md_pub.TbOilwellstimPlanprojEvaluateResult.StimType_Name == data.StimType_Name
            ).delete()
            result.append({
                'DvpUnit_OilStim_PlanProj_Name': data.DvpUnit_OilStim_PlanProj_Name,
                'Well_Name': data.Well_Name,
                'Year': data.Year,
                'StimType_Name': data.StimType_Name,
                'way': 'delete',
                'result': True
            })
            session_pub.commit()
            result[-1].update({
                'result': True
            })
        except:
            print(traceback.print_exc())
            session_pub.rollback()
            result[-1].update({
                'result': False
            })
    return result